<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
      <title>GTL - Graph Template Library: symlist.h Source File</title>
      <link href="doxygen.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <p class="links">  
      <a href="../index.html">Home</a> |
      Documentation |
      <a href="../register.html">Download</a> |
      <a href="../platforms.html">Platforms</a> |
      <a href="../refer.html">Projects</a> |      
      <a href="../lists.html">Mailing Lists</a> |
      <a href="../history.html">Version History</a>
    </p>

<!-- Generated by Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="classes.html"><span>Classes</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>symlist.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//==========================================================================</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">//   symlist.h</span>
<a name="l00004"></a>00004 <span class="comment">//</span>
<a name="l00005"></a>00005 <span class="comment">//==========================================================================</span>
<a name="l00006"></a>00006 <span class="comment">// $Id: symlist.h,v 1.17 2002/12/20 08:26:08 chris Exp $</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#ifndef SYMLIST_H</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define SYMLIST_H</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;GTL/GTL.h&gt;</span> 
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 __GTL_BEGIN_NAMESPACE
<a name="l00016"></a>00016 
<a name="l00020"></a>00020 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00021"></a>00021 <span class="keyword">struct </span>symnode 
<a name="l00022"></a>00022 {
<a name="l00026"></a>00026     symnode()
<a name="l00027"></a>00027     {
<a name="l00028"></a>00028     }
<a name="l00029"></a>00029 
<a name="l00033"></a>00033     symnode(<span class="keyword">const</span> T&amp; n) : data(n)
<a name="l00034"></a>00034     {
<a name="l00035"></a>00035     }
<a name="l00036"></a>00036 
<a name="l00040"></a>00040     symnode* adj[2];
<a name="l00041"></a>00041 
<a name="l00045"></a>00045     T data;
<a name="l00046"></a>00046 };
<a name="l00047"></a>00047 
<a name="l00051"></a>00051 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Ref&gt;
<a name="l00052"></a>00052 <span class="keyword">struct </span>symlist_iterator 
<a name="l00053"></a>00053 {
<a name="l00057"></a>00057     <span class="keyword">typedef</span> symlist_iterator&lt;T, Ref&gt; <span class="keyword">self</span>;
<a name="l00058"></a>00058 
<a name="l00062"></a>00062     <span class="keyword">typedef</span> symnode&lt;T&gt;* linktype;
<a name="l00063"></a>00063 
<a name="l00067"></a>00067     symlist_iterator() : act (0)
<a name="l00068"></a>00068     {
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070 
<a name="l00074"></a>00074     symlist_iterator(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it) : act(it.act), dir(it.dir)
<a name="l00075"></a>00075     {
<a name="l00076"></a>00076     }
<a name="l00077"></a>00077 
<a name="l00081"></a>00081     symlist_iterator(linktype _act, <span class="keywordtype">int</span> _dir) : act(_act), dir(_dir)
<a name="l00082"></a>00082     {
<a name="l00083"></a>00083     }
<a name="l00084"></a>00084     
<a name="l00088"></a>00088     symlist_iterator(linktype _act, linktype _prev) :
<a name="l00089"></a>00089         act(_act),
<a name="l00090"></a>00090         dir (where_not (_act, _prev))
<a name="l00091"></a>00091     {
<a name="l00092"></a>00092     }
<a name="l00093"></a>00093 
<a name="l00097"></a>00097     <span class="keyword">self</span>&amp; operator=(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it)
<a name="l00098"></a>00098     {
<a name="l00099"></a>00099         act = it.act;
<a name="l00100"></a>00100         dir = it.dir;
<a name="l00101"></a>00101         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00102"></a>00102     }
<a name="l00103"></a>00103 
<a name="l00107"></a>00107     <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it)<span class="keyword"> const</span>
<a name="l00108"></a>00108 <span class="keyword">    </span>{
<a name="l00109"></a>00109         <span class="keywordflow">return</span> act == it.act;
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111     
<a name="l00115"></a>00115     <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it)<span class="keyword"> const</span>
<a name="l00116"></a>00116 <span class="keyword">    </span>{
<a name="l00117"></a>00117         <span class="keywordflow">return</span> act != it.act;
<a name="l00118"></a>00118     }
<a name="l00119"></a>00119     
<a name="l00123"></a>00123     Ref operator*() 
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125         <span class="keywordflow">return</span> act-&gt;data;
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127 
<a name="l00131"></a>00131     <span class="keyword">self</span>&amp; operator++();
<a name="l00132"></a>00132 
<a name="l00136"></a>00136     <span class="keyword">self</span>&amp; operator--();
<a name="l00137"></a>00137     
<a name="l00141"></a>00141     <span class="keyword">static</span> <span class="keywordtype">int</span> where(linktype _act, linktype _prev) 
<a name="l00142"></a>00142     {
<a name="l00143"></a>00143         <span class="keywordflow">return</span> _prev == _act-&gt;adj[0] ? 0 : 1;
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145 
<a name="l00149"></a>00149     <span class="keyword">static</span> <span class="keywordtype">int</span> where_not(linktype _act, linktype _prev)
<a name="l00150"></a>00150     {
<a name="l00151"></a>00151         <span class="keywordflow">return</span> _prev == _act-&gt;adj[1] ? 0 : 1;
<a name="l00152"></a>00152     }
<a name="l00153"></a>00153 
<a name="l00157"></a>00157     <span class="keywordtype">void</span> reverse()
<a name="l00158"></a>00158     {
<a name="l00159"></a>00159         dir = 1 - dir;
<a name="l00160"></a>00160     }
<a name="l00161"></a>00161         
<a name="l00165"></a>00165     linktype&amp; next()
<a name="l00166"></a>00166     {
<a name="l00167"></a>00167         <span class="keywordflow">return</span> act-&gt;adj[dir];
<a name="l00168"></a>00168     }
<a name="l00169"></a>00169 
<a name="l00173"></a>00173     linktype&amp; prev()
<a name="l00174"></a>00174     {
<a name="l00175"></a>00175         <span class="keywordflow">return</span> act-&gt;adj[1 - dir];
<a name="l00176"></a>00176     }
<a name="l00177"></a>00177 
<a name="l00181"></a>00181     linktype act;
<a name="l00182"></a>00182 
<a name="l00186"></a>00186     <span class="keywordtype">int</span> dir;
<a name="l00187"></a>00187 };
<a name="l00188"></a>00188 
<a name="l00207"></a>00207 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00208"></a><a class="code" href="a00027.html">00208</a> <span class="keyword">class </span><a class="code" href="a00027.html" title="List which can be reversed in .">symlist</a> 
<a name="l00209"></a>00209 {
<a name="l00210"></a>00210 <span class="keyword">public</span>:
<a name="l00214"></a>00214     <span class="keyword">typedef</span> symlist_iterator&lt;T, T&amp;&gt; iterator;
<a name="l00215"></a>00215 
<a name="l00219"></a>00219     <span class="keyword">typedef</span> symlist_iterator&lt;T, const T&amp;&gt; const_iterator;
<a name="l00220"></a>00220 
<a name="l00224"></a><a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6">00224</a>     <a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6" title="Creates empty symlist.">symlist</a>()
<a name="l00225"></a>00225     {
<a name="l00226"></a>00226         link = <span class="keyword">new</span> symnode&lt;T&gt;;
<a name="l00227"></a>00227         link-&gt;adj[0] = link-&gt;adj[1] = link;
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229 
<a name="l00235"></a>00235     <a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6" title="Creates empty symlist.">symlist</a>(<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; li);
<a name="l00236"></a>00236 
<a name="l00246"></a>00246     <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; <a class="code" href="a00027.html#ab326eda0f6d3a78f193a249342670bc" title="Assignes li to this list.">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; li);
<a name="l00247"></a>00247 
<a name="l00251"></a>00251     <a class="code" href="a00027.html#45c3a0b7f0e996998037fb876effefd4" title="Destructor.">~symlist</a>();
<a name="l00252"></a>00252 
<a name="l00260"></a><a class="code" href="a00027.html#a09d7b1edcb879524dd200cecf7f5f72">00260</a>     <span class="keywordtype">bool</span> <a class="code" href="a00027.html#a09d7b1edcb879524dd200cecf7f5f72" title="Checks whether list is empty.">empty</a>()<span class="keyword"> const</span>
<a name="l00261"></a>00261 <span class="keyword">    </span>{
<a name="l00262"></a>00262         <span class="keywordflow">return</span> link-&gt;adj[0] == link &amp;&amp; link-&gt;adj[1] == link;
<a name="l00263"></a>00263     }
<a name="l00264"></a>00264 
<a name="l00272"></a><a class="code" href="a00027.html#fd4b55616fc20033d4a47684551866e8">00272</a>     T&amp; <a class="code" href="a00027.html#fd4b55616fc20033d4a47684551866e8" title="First element in list.">front</a>()
<a name="l00273"></a>00273     {
<a name="l00274"></a>00274         <span class="keywordflow">return</span> link-&gt;adj[0]-&gt;data;
<a name="l00275"></a>00275     }
<a name="l00276"></a>00276 
<a name="l00284"></a><a class="code" href="a00027.html#bc0570ff78ded9210ac26865519d36e3">00284</a>     T&amp; <a class="code" href="a00027.html#bc0570ff78ded9210ac26865519d36e3" title="Last element in list.">back</a>()
<a name="l00285"></a>00285     {
<a name="l00286"></a>00286         <span class="keywordflow">return</span> link-&gt;adj[1]-&gt;data;
<a name="l00287"></a>00287     }
<a name="l00288"></a>00288 
<a name="l00294"></a><a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0">00294</a>     iterator <a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>()
<a name="l00295"></a>00295     {
<a name="l00296"></a>00296         <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
<a name="l00297"></a>00297     }
<a name="l00298"></a>00298 
<a name="l00304"></a><a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883">00304</a>     iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>()
<a name="l00305"></a>00305     {
<a name="l00306"></a>00306         <span class="keywordflow">return</span> iterator(link, 0);
<a name="l00307"></a>00307     }
<a name="l00308"></a>00308 
<a name="l00314"></a><a class="code" href="a00027.html#7c714327f88430cb7caeb1ecd67afd95">00314</a>     const_iterator <a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>()<span class="keyword"> const</span>
<a name="l00315"></a>00315 <span class="keyword">    </span>{
<a name="l00316"></a>00316         <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
<a name="l00317"></a>00317     }
<a name="l00318"></a>00318 
<a name="l00324"></a><a class="code" href="a00027.html#e7435efb58eeacee68c0268332ed1b0e">00324</a>     const_iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a> ()<span class="keyword"> const</span>
<a name="l00325"></a>00325 <span class="keyword">    </span>{
<a name="l00326"></a>00326         <span class="keywordflow">return</span> const_iterator (link, 0);
<a name="l00327"></a>00327     }
<a name="l00328"></a>00328 
<a name="l00334"></a><a class="code" href="a00027.html#e5250e0c0c2bedee285f72584ddce29d">00334</a>     iterator <a class="code" href="a00027.html#e5250e0c0c2bedee285f72584ddce29d" title="Start iteration through element of list in reverse order.">rbegin</a>()
<a name="l00335"></a>00335     {
<a name="l00336"></a>00336         <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>();
<a name="l00337"></a>00337     }
<a name="l00338"></a>00338 
<a name="l00344"></a><a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6">00344</a>     iterator <a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>()
<a name="l00345"></a>00345     {
<a name="l00346"></a>00346         <span class="keywordflow">return</span> iterator (link, 1);
<a name="l00347"></a>00347     }
<a name="l00348"></a>00348 
<a name="l00354"></a><a class="code" href="a00027.html#52e8efa766be554f4a5a788758c8b2e9">00354</a>     const_iterator <a class="code" href="a00027.html#e5250e0c0c2bedee285f72584ddce29d" title="Start iteration through element of list in reverse order.">rbegin</a>()<span class="keyword"> const</span>
<a name="l00355"></a>00355 <span class="keyword">    </span>{
<a name="l00356"></a>00356         <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>();
<a name="l00357"></a>00357     }
<a name="l00358"></a>00358 
<a name="l00364"></a><a class="code" href="a00027.html#a33168957d1316726012faa6b01fb9d2">00364</a>     const_iterator <a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>()<span class="keyword"> const</span>
<a name="l00365"></a>00365 <span class="keyword">    </span>{
<a name="l00366"></a>00366         <span class="keywordflow">return</span> const_iterator(link, 1);
<a name="l00367"></a>00367     }
<a name="l00368"></a>00368 
<a name="l00377"></a>00377     iterator <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">insert</a> (iterator pos, <span class="keyword">const</span> T&amp; data);
<a name="l00378"></a>00378 
<a name="l00390"></a>00390     <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">splice</a> (iterator pos, iterator it);
<a name="l00391"></a>00391 
<a name="l00404"></a>00404     <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">splice</a> (iterator pos, iterator it, iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>);
<a name="l00405"></a>00405 
<a name="l00413"></a>00413     iterator <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a> (iterator pos);
<a name="l00414"></a>00414 
<a name="l00423"></a>00423     iterator <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a> (iterator it, iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>);
<a name="l00424"></a>00424 
<a name="l00428"></a>00428     <span class="keywordtype">void</span> attach_sublist (iterator, iterator);
<a name="l00429"></a>00429 
<a name="l00433"></a>00433     <span class="keywordtype">void</span> detach_sublist ();
<a name="l00434"></a>00434 
<a name="l00440"></a>00440     <span class="keywordtype">void</span> <a class="code" href="a00027.html#e22b65101604c694e96974cc9579ab78" title="Change the direction of list.">reverse</a> ();
<a name="l00441"></a>00441 <span class="keyword">private</span>:
<a name="l00445"></a>00445     symnode&lt;T&gt;* link;
<a name="l00446"></a>00446 
<a name="l00452"></a>00452     iterator _prev;
<a name="l00453"></a>00453 
<a name="l00459"></a>00459     iterator _next;
<a name="l00460"></a>00460 };
<a name="l00461"></a>00461 
<a name="l00462"></a>00462 
<a name="l00463"></a>00463 <span class="comment">// Implementation Begin</span>
<a name="l00464"></a>00464 
<a name="l00465"></a>00465 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Ref&gt;
<a name="l00466"></a>00466 symlist_iterator&lt;T, Ref&gt;&amp; symlist_iterator&lt;T, Ref&gt;::operator++()
<a name="l00467"></a>00467 {
<a name="l00468"></a>00468     symnode&lt;T&gt;* prev = act; 
<a name="l00469"></a>00469     act = act-&gt;adj[dir];
<a name="l00470"></a>00470     dir = where_not(act, prev);
<a name="l00471"></a>00471     <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00472"></a>00472 }
<a name="l00473"></a>00473 
<a name="l00474"></a>00474 
<a name="l00475"></a>00475 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Ref&gt;
<a name="l00476"></a>00476 symlist_iterator&lt;T, Ref&gt;&amp; symlist_iterator&lt;T, Ref&gt;::operator--()
<a name="l00477"></a>00477 {
<a name="l00478"></a>00478     symnode&lt;T&gt;* prev = act;
<a name="l00479"></a>00479     act = act-&gt;adj[1 - dir];
<a name="l00480"></a>00480     dir = where(act, prev); 
<a name="l00481"></a>00481     <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00482"></a>00482 }
<a name="l00483"></a>00483 
<a name="l00484"></a>00484 
<a name="l00485"></a>00485 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00486"></a><a class="code" href="a00027.html#5c17d54592dac03b2c4d940a10153797">00486</a> <a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6" title="Creates empty symlist.">symlist&lt;T&gt;::symlist</a> (<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; l)
<a name="l00487"></a>00487 {
<a name="l00488"></a>00488     link = <span class="keyword">new</span> symnode&lt;T&gt;;
<a name="l00489"></a>00489     link-&gt;adj[0] = link-&gt;adj[1] = link;    
<a name="l00490"></a>00490     
<a name="l00491"></a>00491     const_iterator it = l.<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>();
<a name="l00492"></a>00492     const_iterator e = l.<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
<a name="l00493"></a>00493 
<a name="l00494"></a>00494     <span class="keywordflow">while</span> (it != e)
<a name="l00495"></a>00495     {
<a name="l00496"></a>00496         <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">insert</a>(<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>(), *it);
<a name="l00497"></a>00497         ++it;
<a name="l00498"></a>00498     }
<a name="l00499"></a>00499 }
<a name="l00500"></a>00500 
<a name="l00501"></a>00501 
<a name="l00502"></a>00502 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00503"></a><a class="code" href="a00027.html#45c3a0b7f0e996998037fb876effefd4">00503</a> <a class="code" href="a00027.html#45c3a0b7f0e996998037fb876effefd4" title="Destructor.">symlist&lt;T&gt;::~symlist</a>()
<a name="l00504"></a>00504 {
<a name="l00505"></a>00505     <span class="keywordflow">if</span> (_next == iterator())
<a name="l00506"></a>00506     {
<a name="l00507"></a>00507         <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a> (<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>(), <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>());
<a name="l00508"></a>00508     }
<a name="l00509"></a>00509     <span class="keywordflow">else</span>
<a name="l00510"></a>00510     {
<a name="l00511"></a>00511         detach_sublist();
<a name="l00512"></a>00512     }
<a name="l00513"></a>00513     
<a name="l00514"></a>00514     <span class="keyword">delete</span> link;
<a name="l00515"></a>00515 }
<a name="l00516"></a>00516 
<a name="l00517"></a>00517 
<a name="l00518"></a>00518 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00519"></a><a class="code" href="a00027.html#ab326eda0f6d3a78f193a249342670bc">00519</a> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; <a class="code" href="a00027.html#ab326eda0f6d3a78f193a249342670bc" title="Assignes li to this list.">symlist&lt;T&gt;::operator=</a>(<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; l) 
<a name="l00520"></a>00520 {
<a name="l00521"></a>00521     <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a>(<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>(), <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>());
<a name="l00522"></a>00522 
<a name="l00523"></a>00523     const_iterator it = l.<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>();
<a name="l00524"></a>00524     const_iterator e = l.<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
<a name="l00525"></a>00525 
<a name="l00526"></a>00526     <span class="keywordflow">while</span> (it != e)
<a name="l00527"></a>00527     {
<a name="l00528"></a>00528         <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">insert</a>(<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>(), *it);
<a name="l00529"></a>00529         ++it;
<a name="l00530"></a>00530     }
<a name="l00531"></a>00531     
<a name="l00532"></a>00532     <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00533"></a>00533 }
<a name="l00534"></a>00534 
<a name="l00535"></a>00535 
<a name="l00536"></a>00536 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00537"></a>00537 symlist_iterator&lt;T, T&amp;&gt; <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">symlist&lt;T&gt;::insert</a>(
<a name="l00538"></a>00538     symlist_iterator&lt;T,T&amp;&gt; pos,
<a name="l00539"></a>00539     <span class="keyword">const</span> T&amp; ins)
<a name="l00540"></a>00540 {
<a name="l00541"></a>00541     iterator prev = pos;
<a name="l00542"></a>00542     --prev;
<a name="l00543"></a>00543     symnode&lt;T&gt;* n = <span class="keyword">new</span> symnode&lt;T&gt;(ins);
<a name="l00544"></a>00544     n-&gt;adj[0] = pos.act;
<a name="l00545"></a>00545     n-&gt;adj[1] = prev.act;
<a name="l00546"></a>00546 
<a name="l00547"></a>00547     <span class="keywordflow">if</span> (pos == prev)
<a name="l00548"></a>00548     {
<a name="l00549"></a>00549         pos = prev;
<a name="l00550"></a>00550     }
<a name="l00551"></a>00551 
<a name="l00552"></a>00552     pos.prev() = n;
<a name="l00553"></a>00553     prev.next() = n;
<a name="l00554"></a>00554 
<a name="l00555"></a>00555     <span class="keywordflow">return</span> iterator(n, 0);
<a name="l00556"></a>00556 }
<a name="l00557"></a>00557 
<a name="l00558"></a>00558 
<a name="l00559"></a>00559 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00560"></a>00560 <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">symlist&lt;T&gt;::splice</a>(symlist_iterator&lt;T, T&amp;&gt; pos,
<a name="l00561"></a>00561                         symlist_iterator&lt;T, T&amp;&gt; beg,
<a name="l00562"></a>00562                         symlist_iterator&lt;T, T&amp;&gt; <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>) 
<a name="l00563"></a>00563 {
<a name="l00564"></a>00564     <span class="keywordflow">if</span> (beg != end)
<a name="l00565"></a>00565     {
<a name="l00566"></a>00566         iterator prev = beg;
<a name="l00567"></a>00567         --prev;
<a name="l00568"></a>00568         iterator last = end;
<a name="l00569"></a>00569         --last;
<a name="l00570"></a>00570 
<a name="l00571"></a>00571         <span class="comment">//</span>
<a name="l00572"></a>00572         <span class="comment">// The following seems to be rather senseless, but it is required</span>
<a name="l00573"></a>00573         <span class="comment">// since two iterator are equal, iff the point to the same element.</span>
<a name="l00574"></a>00574         <span class="comment">// This implies that they might have different directions. Suppose</span>
<a name="l00575"></a>00575         <span class="comment">// that prev == end is true and they have different directions,</span>
<a name="l00576"></a>00576         <span class="comment">// than prev.next() and end.prev() return the same element !! Thus</span>
<a name="l00577"></a>00577         <span class="comment">// the assignment prev = end corrects this, since the direction</span>
<a name="l00578"></a>00578         <span class="comment">// gets copied, too.</span>
<a name="l00579"></a>00579         <span class="comment">//</span>
<a name="l00580"></a>00580         <span class="keywordflow">if</span> (prev == end)
<a name="l00581"></a>00581         {
<a name="l00582"></a>00582             prev = end;
<a name="l00583"></a>00583         }
<a name="l00584"></a>00584             
<a name="l00585"></a>00585         prev.next() = end.act;
<a name="l00586"></a>00586         end.prev() = prev.act;
<a name="l00587"></a>00587 
<a name="l00588"></a>00588         prev = pos;
<a name="l00589"></a>00589         --prev;
<a name="l00590"></a>00590 
<a name="l00591"></a>00591         <span class="keywordflow">if</span> (pos == prev)
<a name="l00592"></a>00592         {
<a name="l00593"></a>00593             pos = prev;
<a name="l00594"></a>00594         }
<a name="l00595"></a>00595 
<a name="l00596"></a>00596         <span class="keywordflow">if</span> (last == beg)
<a name="l00597"></a>00597         {
<a name="l00598"></a>00598             last = beg;
<a name="l00599"></a>00599         }
<a name="l00600"></a>00600         
<a name="l00601"></a>00601         prev.next() = beg.act;
<a name="l00602"></a>00602         beg.prev() = prev.act;
<a name="l00603"></a>00603         pos.prev() = last.act;
<a name="l00604"></a>00604         last.next() = pos.act;
<a name="l00605"></a>00605     }
<a name="l00606"></a>00606 }
<a name="l00607"></a>00607 
<a name="l00608"></a>00608 
<a name="l00609"></a>00609 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00610"></a>00610 <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">symlist&lt;T&gt;::splice</a>(symlist_iterator&lt;T,T&amp;&gt; pos, 
<a name="l00611"></a>00611                         symlist_iterator&lt;T,T&amp;&gt; beg)
<a name="l00612"></a>00612 {
<a name="l00613"></a>00613     iterator tmp = beg;
<a name="l00614"></a>00614     ++tmp;
<a name="l00615"></a>00615     <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">splice</a>(pos, beg, tmp);
<a name="l00616"></a>00616 }
<a name="l00617"></a>00617 
<a name="l00618"></a>00618 
<a name="l00619"></a>00619 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00620"></a>00620 symlist_iterator&lt;T,T&amp;&gt; <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">symlist&lt;T&gt;::erase</a>(symlist_iterator&lt;T,T&amp;&gt; pos) 
<a name="l00621"></a>00621 {
<a name="l00622"></a>00622     assert (pos.act != link);
<a name="l00623"></a>00623     iterator prev = pos;
<a name="l00624"></a>00624     --prev;
<a name="l00625"></a>00625     iterator next = pos;
<a name="l00626"></a>00626     ++next;
<a name="l00627"></a>00627     
<a name="l00628"></a>00628     <span class="keywordflow">if</span> (next == prev)
<a name="l00629"></a>00629     {
<a name="l00630"></a>00630         next = prev;
<a name="l00631"></a>00631     }
<a name="l00632"></a>00632 
<a name="l00633"></a>00633     next.prev() = prev.act;
<a name="l00634"></a>00634     prev.next() = next.act;
<a name="l00635"></a>00635 
<a name="l00636"></a>00636     <span class="keyword">delete</span> (pos.act);
<a name="l00637"></a>00637 
<a name="l00638"></a>00638     <span class="keywordflow">return</span> next;
<a name="l00639"></a>00639 }
<a name="l00640"></a>00640 
<a name="l00641"></a>00641 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00642"></a>00642 symlist_iterator&lt;T,T&amp;&gt; <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">symlist&lt;T&gt;::erase</a>(symlist_iterator&lt;T,T&amp;&gt; beg, 
<a name="l00643"></a>00643                                          symlist_iterator&lt;T,T&amp;&gt; end)
<a name="l00644"></a>00644 {
<a name="l00645"></a>00645     iterator prev = beg;
<a name="l00646"></a>00646     --prev;
<a name="l00647"></a>00647     iterator it = beg;
<a name="l00648"></a>00648     symnode&lt;T&gt;* act;
<a name="l00649"></a>00649 
<a name="l00650"></a>00650     <span class="keywordflow">while</span> (it != end)
<a name="l00651"></a>00651     {
<a name="l00652"></a>00652         assert (it.act != link);
<a name="l00653"></a>00653         act = it.act;
<a name="l00654"></a>00654         ++it;
<a name="l00655"></a>00655         <span class="keyword">delete</span> (act);
<a name="l00656"></a>00656     }
<a name="l00657"></a>00657 
<a name="l00658"></a>00658     <span class="keywordflow">if</span> (prev == end)
<a name="l00659"></a>00659     {
<a name="l00660"></a>00660         prev = end;
<a name="l00661"></a>00661     }   
<a name="l00662"></a>00662     
<a name="l00663"></a>00663     end.prev() = prev.act;
<a name="l00664"></a>00664     prev.next() = end.act;
<a name="l00665"></a>00665    
<a name="l00666"></a>00666     <span class="keywordflow">return</span> end;
<a name="l00667"></a>00667 }    
<a name="l00668"></a>00668 
<a name="l00669"></a>00669 
<a name="l00670"></a>00670 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00671"></a>00671 <span class="keywordtype">void</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;::attach_sublist</a>(symlist_iterator&lt;T,T&amp;&gt; it, 
<a name="l00672"></a>00672                                 symlist_iterator&lt;T,T&amp;&gt; end) 
<a name="l00673"></a>00673 { 
<a name="l00674"></a>00674     assert (<a class="code" href="a00027.html#a09d7b1edcb879524dd200cecf7f5f72" title="Checks whether list is empty.">empty</a>());
<a name="l00675"></a>00675     iterator last = end;
<a name="l00676"></a>00676     --last;
<a name="l00677"></a>00677     _prev = it;
<a name="l00678"></a>00678     --_prev;
<a name="l00679"></a>00679     _next = end;
<a name="l00680"></a>00680 
<a name="l00681"></a>00681     <span class="keywordflow">if</span> (it == last)
<a name="l00682"></a>00682     {
<a name="l00683"></a>00683         it = last;
<a name="l00684"></a>00684     }
<a name="l00685"></a>00685 
<a name="l00686"></a>00686     link-&gt;adj[0] = it.act;
<a name="l00687"></a>00687     it.prev() = link;
<a name="l00688"></a>00688     link-&gt;adj[1] = last.act;
<a name="l00689"></a>00689     last.next() = link;
<a name="l00690"></a>00690 }   
<a name="l00691"></a>00691 
<a name="l00692"></a>00692     
<a name="l00693"></a>00693 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00694"></a>00694 <span class="keywordtype">void</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;::detach_sublist</a>() 
<a name="l00695"></a>00695 {
<a name="l00696"></a>00696     <span class="keywordflow">if</span> (_next != iterator())
<a name="l00697"></a>00697     {
<a name="l00698"></a>00698         iterator it(<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>());
<a name="l00699"></a>00699         iterator e(<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>());
<a name="l00700"></a>00700         
<a name="l00701"></a>00701         --e;
<a name="l00702"></a>00702         
<a name="l00703"></a>00703         <span class="keywordflow">if</span> (e == it)
<a name="l00704"></a>00704         {
<a name="l00705"></a>00705             e = it;
<a name="l00706"></a>00706         }
<a name="l00707"></a>00707 
<a name="l00708"></a>00708         _prev.next() = it.act;
<a name="l00709"></a>00709         it.prev() = _prev.act;
<a name="l00710"></a>00710         _next.prev() = e.act;
<a name="l00711"></a>00711         e.next() = _next.act;
<a name="l00712"></a>00712         link-&gt;adj[0] = link-&gt;adj[1] = link;
<a name="l00713"></a>00713 
<a name="l00714"></a>00714         _next = iterator();
<a name="l00715"></a>00715         _prev = iterator();
<a name="l00716"></a>00716     }
<a name="l00717"></a>00717 }
<a name="l00718"></a>00718 
<a name="l00719"></a>00719 
<a name="l00720"></a>00720 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00721"></a><a class="code" href="a00027.html#e22b65101604c694e96974cc9579ab78">00721</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00027.html#e22b65101604c694e96974cc9579ab78" title="Change the direction of list.">symlist&lt;T&gt;::reverse</a>()
<a name="l00722"></a>00722 {
<a name="l00723"></a>00723     symnode&lt;T&gt;* tmp = link-&gt;adj[0];
<a name="l00724"></a>00724     link-&gt;adj[0] = link-&gt;adj[1];
<a name="l00725"></a>00725     link-&gt;adj[1] = tmp;
<a name="l00726"></a>00726 }
<a name="l00727"></a>00727 
<a name="l00728"></a>00728 <span class="comment">// Implementation End</span>
<a name="l00729"></a>00729 
<a name="l00730"></a>00730 __GTL_END_NAMESPACE
<a name="l00731"></a>00731 
<a name="l00732"></a>00732 <span class="preprocessor">#endif // SYMLIST_H</span>
<a name="l00733"></a>00733 <span class="preprocessor"></span>
<a name="l00734"></a>00734 <span class="comment">//--------------------------------------------------------------------------</span>
<a name="l00735"></a>00735 <span class="comment">//   end of file</span>
<a name="l00736"></a>00736 <span class="comment">//--------------------------------------------------------------------------</span>
</pre></div>    <p class="links">
      <a href="http://www.uni-passau.de/">University of Passau</a>
      &nbsp;-&nbsp;
      <a href="http://www.fmi.uni-passau.de/">FMI</a>
      &nbsp;-&nbsp;
      <a href="http://www.fmi.uni-passau.de/fmi/lehrstuehle/brandenburg/">Theoretical
	Computer Science</a>
    </p>
  <div class="copyright">
      Design &copy; 2002, 2003 <a href="mailto:raitner@fmi.uni-passau.de">Marcus Raitner</a>,  University of Passau 
  </div>
</body>
</html>
